<template>
  <div class="upload-img">
    <div class="upload-list" v-for="(item, index) in uploadList" :key="index">
      <template>
        <img :src="item.url">
        <div class="upload-list-cover">
          <Icon type="ios-eye-outline" @click.native="handleView(item.name)"></Icon>
        </div>
      </template>
    </div>
    <Modal title="查看图片" v-model="visible">
      <img :src="cdnUrl + '/' + imgName" v-if="visible" style="width: 100%">
    </Modal>
  </div>
</template>

<script>
  import { uploadUrl, cdnUrl } from '@/config'

  export default {
    name: 'view-img',
    props: [
      'defaultImageList'
    ],
    data () {
      return {
        uploadUrl,
        cdnUrl,
        imgName: '',
        visible: false,
        uploadList: []
      }
    },
    methods: {
      handleView (name) {
        this.imgName = name
        this.visible = true
      }
    },
    mounted () {
      this.uploadList = this.defaultImageList
    }
  }
</script>

<style lang="less">
  .upload-img {
    .upload-list {
      display: inline-block;
      width: 100px;
      height: 100px;
      text-align: center;
      line-height: 100px;
      border: 1px solid transparent;
      border-radius: 4px;
      overflow: hidden;
      background: #fff;
      position: relative;
      box-shadow: 0 1px 1px rgba(0,0,0,.2);
      margin-right: 4px;
      img {
        width: 100%;
        height: 100%;
      }
    }

    .upload-list-cover {
      display: none;
      position: absolute;
      top: 0;
      bottom: 0;
      left: 0;
      right: 0;
      background: rgba(0,0,0,.6);
      i {
        color: #fff;
        font-size: 26px;
        cursor: pointer;
        margin: 0 8px;
      }
    }

    .upload-list:hover .upload-list-cover {
        display: block;
    }

     .ivu-upload {
      width: 100px;
      height: 100px;
      .ivu-icon {
        margin-top: 20px;
      }
    }
  }
</style>
